﻿(function () {
  'use strict';
  var controllerId = 'dashboard';
  angular.module('ng4model').controller(controllerId, ['common', 'datacontext', dashboard]);

  function dashboard(common, datacontext) {
    var getLogFn = common.logger.getLogFn;
    var log = getLogFn(controllerId);

    var vm = this;
    vm.news = {
      title: 'ng4model',
      description: 'You have 2 new invitations.'
    };
    vm.messageCount = 0;
    vm.members = [];
    vm.projects = [];
    vm.texts = [];
    vm.title = 'Dashboard';

    activate();

    function activate() {
      var promises = [getMessageCount(), getAllMembers(), getProjects(), getAllOpuses()];
      common.activateController(promises, controllerId)
          .then(function () { log('Activated Dashboard View'); });
    }

    function getMessageCount() {
      return datacontext.getMessageCount().then(function (data) {
        return vm.messageCount = data;
      });
    }

    function getAllMembers() {
      return datacontext.getAllMembers().then(function (data) {
        return vm.members = data;
      });
    }

    function getProjects() {
      return datacontext.getProjects().then(function (data) {
        return vm.projects = data;
      });
    }

    function getAllOpuses() {
      return datacontext.getAllOpuses().then(function (data) {
        return vm.texts = data;
      });
    }
  }
})();